home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cfengine-1.5.3 / src / cflex.l.in < prev    next >
Encoding:
Text File  |  1999-10-20  |  21.5 KB  |  704 lines

  1. %{
  2. /* cfengine for GNU
  3.  
  4.         Copyright (C) 1995
  5.         Free Software Foundation, Inc.
  6.  
  7.    This file is part of GNU cfengine - written and maintained 
  8.    by Mark Burgess, Dept of Computing and Engineering, Oslo College,
  9.    Dept. of Theoretical physics, University of Oslo
  10.  
  11.    This program is free software; you can redistribute it and/or modify it
  12.    under the terms of the GNU General Public License as published by the
  13.    Free Software Foundation; either version 2, or (at your option) any
  14.    later version.
  15.  
  16.    This program is distributed in the hope that it will be useful,
  17.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.    GNU General Public License for more details.
  20.  
  21.   You should have received a copy of the GNU General Public License
  22.   along with this program; if not, write to the Free Software
  23.   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
  24.  
  25. */
  26.  
  27.  
  28. /*******************************************************************/
  29. /*                                                                 */
  30. /*  LEXER for cfengine                                             */
  31. /*                                                                 */
  32. /*                                                                 */
  33. /*******************************************************************/
  34.  
  35.  
  36.  /* Here we define a two state lexer. The states exclude
  37.     certain regular expression matches so as to more easily
  38.     distinguish between class constructions like 
  39.  
  40.        compound.class::
  41.  
  42.     identifiers like
  43.  
  44.        group = ( .... )
  45.  
  46.     and items inside the parentheses like
  47.  
  48.        .... = ( alpha beta gamma )
  49.  
  50.     The state
  51.     <IDENT> recognizes identifiers and <INITIAL> recognizes what
  52.     is an item in a LisT.
  53.  
  54.  */
  55.  
  56.  
  57. #include "y.tab.h"       /* Note that BISON produces a file called */
  58. #include "cf.defs.h"     /* mconfig.tab.h instead of y.tab.h !!    */
  59. #include "cf.extern.h"
  60.  
  61.  
  62.   /* Note the %o %a declarations to allow more internal workspace */
  63.  
  64. %}
  65.  
  66. %s IDENT
  67. %o 24000
  68. %a 16000
  69. %p 8000
  70. %n 800
  71.  
  72. space     [ \t]+
  73. comment   #.*
  74. linedir   #line[ \t]+[0-9]+.*
  75. qstring   \"[^"\n]*\"
  76. sqstring  \'[^'\n]*\'
  77. bqstring  `[^`\n]*`
  78. item      [+]?[-.,@a-zA-Z0-9_@EIGHTBIT@]+
  79. id        [.|!,;a-zA-Z0-9_@EIGHTBIT@]+
  80. classt    [.|!,;a-zA-Z0-9_()@EIGHTBIT@]+::
  81. path      [-:.,;/a-zA-Z0-9_@EIGHTBIT@]+
  82. varpath   [/$<][-.,;a-zA-Z0-9<>@+:$*?(){}/_@EIGHTBIT@]*
  83. varitem   [-.a-zA-Z0-9<>$*?()={}/_@EIGHTBIT@]*
  84. wildcard  [^\135 ()>\t\n|&@\175@EIGHTBIT@]+
  85. newline   [\n]
  86. lbrack    \(
  87. rbrack    \)
  88. lbrace    \{
  89. rbrace    \}
  90. equals    =
  91. forcearrow ->!
  92. lforcearrow \+>!
  93. arrow     ->
  94. larrow    \+>
  95.  
  96. %%
  97.  
  98. admit:                 {
  99.                        DaemonOnly;
  100.  
  101.                        BEGIN IDENT;
  102.                        SetAction(admit);
  103.                        return ADMIT;
  104.                        }
  105.  
  106.  
  107. grant:                 {
  108.                        DaemonOnly;
  109.  
  110.                        BEGIN IDENT;
  111.                        SetAction(admit);
  112.                        return ADMIT;
  113.                        }
  114.  
  115. deny:                  {
  116.                        DaemonOnly;
  117.  
  118.                        BEGIN IDENT;
  119.                        SetAction(deny);
  120.                        return DENY;
  121.                        }
  122.  
  123. control:               {
  124.                        BEGIN IDENT;
  125.                        SetAction(control);
  126.                        return CONTROL;
  127.                        }
  128.  
  129. groups:                {
  130.                        BEGIN IDENT;
  131.                        SetAction(groups);
  132.                        return GROUPS;
  133.                        }
  134.  
  135. classes:               {                       /* Synonym for groups */
  136.                        BEGIN IDENT;
  137.                        SetAction(groups);
  138.                        return GROUPS;
  139.                        }
  140.  
  141. acl:                   {
  142.                        CfengineOnly;
  143.  
  144.                        BEGIN IDENT;
  145.                        SetAction(acls);
  146.                        return ACL;
  147.                        }
  148.  
  149.  
  150. copy:                  {
  151.                        CfengineOnly;
  152.  
  153.                        BEGIN INITIAL;
  154.                        SetAction(image);
  155.                        return IMAGE;
  156.                        }
  157.  
  158. resolve:               {
  159.                        CfengineOnly;
  160.  
  161.                        BEGIN INITIAL;
  162.                        SetAction(resolve);
  163.                        return RESOLVE;
  164.                        }
  165.  
  166.  
  167. files:                 {
  168.                        CfengineOnly;
  169.  
  170.                        BEGIN INITIAL;
  171.                        SetAction(files);
  172.                        return FILES;
  173.                        }
  174.  
  175. tidy:                  {
  176.                        CfengineOnly;
  177.  
  178.                        BEGIN INITIAL;
  179.                        SetAction(tidy);
  180.                        return TIDY;
  181.                        }
  182.  
  183. homeservers:           {
  184.                        CfengineOnly;
  185.  
  186.                        BEGIN INITIAL;
  187.                        SetAction(homeservers);
  188.                        return HOMESERVERS;
  189.                        }
  190.  
  191. binservers:            {
  192.                        CfengineOnly;
  193.  
  194.                        BEGIN INITIAL;
  195.                        SetAction(binservers);
  196.                        return BINSERVERS;
  197.                        }
  198.  
  199. mailserver:            {
  200.                        CfengineOnly;
  201.  
  202.                        BEGIN INITIAL;
  203.                        SetAction(mailserver);
  204.                        return MAILSERVER;
  205.                        }
  206.  
  207. disks:
  208. required:              {
  209.                        CfengineOnly;
  210.  
  211.                        BEGIN INITIAL;
  212.                        SetAction(required);
  213.                        return REQUIRED;
  214.                        }
  215.  
  216. mountables:            {
  217.                        CfengineOnly;
  218.  
  219.                        BEGIN INITIAL;
  220.                        SetAction(mountables);
  221.                        return MOUNTABLES;
  222.                        }
  223.  
  224. links:                 {
  225.                        CfengineOnly;
  226.  
  227.                        BEGIN INITIAL;
  228.                        SetAction(links);
  229.                        return LINKS;
  230.                        }
  231.  
  232. import:                {
  233.                        CfengineOnly;
  234.  
  235.                        BEGIN INITIAL;
  236.                        SetAction(import);
  237.                        return IMPORT;
  238.                        }
  239.  
  240. shellcommands:          {
  241.                         CfengineOnly;
  242.  
  243.                         BEGIN INITIAL;
  244.                         SetAction(shellcommands);
  245.                         return SCRIPTS;
  246.                         }
  247.  
  248. disable:               {
  249.                        CfengineOnly;
  250.  
  251.                        BEGIN INITIAL;
  252.                        SetAction(disable);
  253.                        return DISABLE;
  254.                        }
  255.  
  256. directories:           {
  257.                        CfengineOnly;
  258.  
  259.                        BEGIN INITIAL;
  260.                        SetAction(makepath);
  261.                        return MAKEPATH;
  262.                        }
  263.  
  264. ignore:                {
  265.                        CfengineOnly;
  266.  
  267.                        BEGIN INITIAL;
  268.                        SetAction(ignore);
  269.                        return FILEIGNORE;
  270.                        }
  271.  
  272. interfaces:           {
  273.                 CfengineOnly;
  274.  
  275.                 BEGIN INITIAL;
  276.                 SetAction(interfaces);
  277.                 return INTERFACES;
  278.                 }
  279.  
  280. broadcast:             {
  281.                        CfengineOnly;
  282.  
  283.                        BEGIN INITIAL;
  284.                        SetAction(broadcast);
  285.                        return BROADCAST;
  286.                        }
  287.  
  288. defaultroute:          {
  289.                        CfengineOnly;
  290.  
  291.                        BEGIN INITIAL;
  292.                        SetAction(defaultroute);
  293.                        return DEFAULTROUTE;
  294.                        }
  295.  
  296. miscmounts:            {
  297.                        CfengineOnly;
  298.  
  299.                        BEGIN INITIAL;
  300.                        SetAction(misc_mounts);
  301.                        return MISCMOUNTS;
  302.                        }
  303.  
  304. unmount:               {
  305.                        CfengineOnly;
  306.  
  307.                        BEGIN INITIAL;
  308.                        SetAction(unmounta);
  309.                        return(UNMOUNT);
  310.                        }
  311.  
  312.  
  313. editfiles:             {
  314.                        CfengineOnly;
  315.  
  316.                        BEGIN INITIAL;
  317.                        SetAction(editfiles);
  318.                        return EDITFILES;
  319.                        }
  320.  
  321. processes:             {
  322.                        CfengineOnly;
  323.  
  324.                        BEGIN INITIAL;
  325.                        SetAction(processes);
  326.                        return PROCESSES;
  327.                        }
  328.  
  329.  
  330. {newline}              {
  331.                        LINENUMBER++;
  332.                        }
  333.  
  334. {space}                {
  335.                        }
  336.  
  337. {linedir}              {
  338.                        ResetLine((char *)yytext+6);
  339.                        } 
  340.  
  341. {comment}              {
  342.                        }
  343.  
  344.  
  345. {lforcearrow}          {
  346.                        strcpy(LINKFROM,CURRENTPATH);
  347.                        ACTION_IS_LINKCHILDREN = true;
  348.                        FORCELINK=true;
  349.                        return LARROW;
  350.                        }
  351.  
  352.  
  353. {forcearrow}           {
  354.                        strcpy(LINKFROM,CURRENTPATH);
  355.                        ACTION_IS_LINK = true;
  356.                        FORCELINK=true;
  357.                        return ARROW;
  358.                        }
  359.  
  360. {arrow}                {
  361.                        strcpy(LINKFROM,CURRENTPATH);
  362.                        ACTION_IS_LINK = true;
  363.                        FORCELINK=false;
  364.                        return ARROW;
  365.                        }
  366.  
  367.  
  368. {larrow}               {
  369.                        strcpy(LINKFROM,CURRENTPATH);
  370.                        ACTION_IS_LINKCHILDREN = true;
  371.                        FORCELINK=false;
  372.                        return LARROW;
  373.                        }
  374.  
  375.  
  376. {equals}               {
  377.                        return EQUALS;
  378.                        }
  379.  
  380.  
  381. {id}::                 {
  382.                        Debug1("Class:: %s\n",yytext);   
  383.  
  384.  
  385.                        yytext[strlen((char *)yytext)-2] = '\0';
  386.                        HandleClass(yytext);
  387.                        return PARSECLASS;
  388.                        }
  389.  
  390.  
  391. {classt}               {
  392.                        Debug1("Class:: %s\n",yytext);   
  393.  
  394.                        yytext[strlen((char *)yytext)-2] = '\0';
  395.                        HandleClass(yytext);
  396.                        return PARSECLASS;
  397.                        }
  398.  
  399. <IDENT>{id}            {
  400.                        HandleId(yytext);
  401.                        return(ID);
  402.                        }
  403.  
  404.  
  405. {lbrack}               {
  406.                        Debug1("LEFTBRACK\n");
  407.                        BEGIN INITIAL;
  408.                        return LBRACK;
  409.                        }
  410.  
  411. {lbrace}               {
  412.                        return LBRACE;
  413.                        }
  414.  
  415. {rbrack}               {
  416.                        Debug1("RIGHTBRACK\n");
  417.                        BEGIN IDENT;
  418.                        return RBRACK;
  419.                        }
  420.  
  421. {rbrace}               {
  422.                        if (EDITGROUPLEVEL != 0)
  423.                           {
  424.                           yyerror("Editfiles Begin/End mismatch before or at line");
  425.                           }
  426.  
  427.                        if (SEARCHREPLACELEVEL != 0)
  428.                           {
  429.                           yyerror("ReplaceAll/With mismatch before or at line");
  430.                           }
  431.  
  432.                        if (FOREACHLEVEL != 0)
  433.                           {
  434.                           yyerror("ForEachLineIn/EndLoop mismatch before or at line");
  435.                           }
  436.  
  437.                        if (MOUNT_FROM || MOUNT_ONTO)
  438.                           {
  439.                           yyerror("Missing rw/ro mode in mount syntax");
  440.                           MOUNT_FROM = false;
  441.                           MOUNT_ONTO = false;
  442.                           }
  443.  
  444.                        
  445.                        return RBRACE;
  446.                        }
  447.  
  448.  
  449. <INITIAL>{item}        {
  450.                        if (ACTION == shellcommands)
  451.                           {
  452.                           yyerror("Shell commands must be quoted strings");
  453.                           }
  454.  
  455.                        if (ACTION == editfiles)
  456.                           {
  457.                           if (strcmp((char *)yytext,"EndGroup") == 0 || 
  458.                               strcmp((char *)yytext,"GotoLastLine") == 0 || 
  459.                               strcmp((char *)yytext,"AutoCreate") == 0  ||
  460.                               strcmp((char *)yytext,"EndLoop") == 0  ||
  461.                               strcmp((char *)yytext,"CatchAbort") == 0  ||
  462.                               strcmp((char *)yytext,"EmptyEntireFilePlease") == 0)
  463.                              {
  464.                              HandleEdit(CURRENTPATH,yytext,NULL);
  465.                              return ITEM;
  466.                              }
  467.                           }
  468.  
  469.                        if (ACTION != control && strcmp((char *)yytext,"home") == 0)
  470.                           {
  471.                           if (DEBUG || D1)
  472.                              {
  473.                              printf("SPECIAL VARIABLE home\n");
  474.                              }
  475.                           HandlePath(yytext);
  476.                           return PATH;
  477.                           }
  478.                        else if (ACTION == tidy)
  479.                           {
  480.                           if (yytext[0] == '\\')       /* ignore \ in \# */
  481.                              {
  482.                              HandleWildcard(yytext+1);
  483.                              }
  484.                           else
  485.                              {
  486.                              HandleWildcard(yytext);
  487.                              }
  488.                           return WILDCARD;
  489.                           }
  490.                        else
  491.                           {
  492.                           HandleItem(yytext);
  493.                           return ITEM;
  494.                           }
  495.                        }
  496.  
  497.  
  498. <INITIAL>{path}        {
  499.                        if (ACTION == shellcommands)
  500.                           {
  501.                           yyerror("Shell commands must be quoted strings");
  502.                           }
  503.  
  504.                        if (strncmp("home",(char *)yytext,4)==0)
  505.                           {
  506.                           HandlePath(yytext);
  507.                           return PATH;
  508.                           }
  509.  
  510.                        if (ACTION == control)
  511.                           {
  512.                           HandleItem(yytext);
  513.                           return ITEM;
  514.                           }
  515.  
  516.                        if (ACTION != mountables  && ACTION != mailserver &&
  517.                            ACTION != misc_mounts &&  ACTION != unmounta && yytext[0] != '/')
  518.                           {
  519.                           if (CONTROLVAR == cfhomepat)
  520.                              {
  521.                              HandleWildcard(yytext);
  522.                              return WILDCARD;
  523.                              }
  524.  
  525.                           if (ACTION_IS_LINK || ACTION_IS_LINKCHILDREN)
  526.                              {
  527.                              HandlePath(yytext);
  528.                              return PATH;
  529.                              }
  530.  
  531.                           sprintf(ERROR,"%s is not an absolute pathname",yytext);
  532.                           yyerror(ERROR);
  533.                           }
  534.  
  535.                        HandlePath(yytext);
  536.                        return PATH;
  537.                        }
  538.  
  539. {qstring}              {
  540.                        if (ACTION == editfiles)
  541.                           {
  542.                           *(yytext+strlen((char *)yytext)-1) = '\0';
  543.                           HandleEdit(CURRENTPATH,CURRENTITEM,yytext+1);
  544.                           return QSTRING;
  545.                           }
  546.                        else if (ACTION == groups)
  547.                           {
  548.                           HandleItem(yytext);
  549.                           return ITEM;
  550.                           }
  551.                        else if (ACTION == control)
  552.                           {
  553.                           *(yytext+strlen((char *)yytext)-1) = '\0';
  554.                           HandleItem(yytext+1);
  555.                           Debug1("Quoted macro string %s\n",yytext+1);
  556.                           return QSTRING;
  557.                           }
  558.                        else
  559.                           {
  560.                           *(yytext+strlen((char *)yytext)-1) = '\0';
  561.  
  562.                           if (yytext[1] == '/')
  563.                              {
  564.                              HandlePath(yytext+1);
  565.                              }
  566.                           else
  567.                              {
  568.                              HandleItem(yytext+1);
  569.                              }
  570.                           return QSTRING;
  571.                           }
  572.                        }
  573.  
  574. {sqstring}             {
  575.                        if (ACTION == editfiles)
  576.                           {
  577.                           *(yytext+strlen((char *)yytext)-1) = '\0';
  578.                           HandleEdit(CURRENTPATH,CURRENTITEM,yytext+1);
  579.                           return QSTRING;
  580.                           }
  581.                        else if (ACTION == groups)
  582.                           {
  583.                           HandleItem(yytext);
  584.                           return ITEM;
  585.                           }
  586.                        else if (ACTION == control)
  587.                           {
  588.                           *(yytext+strlen((char *)yytext)-1) = '\0';
  589.                           HandleItem(yytext+1);
  590.                           Debug1("Quoted macro string %s\n",yytext+1);
  591.                           return QSTRING;
  592.                           }
  593.                        else
  594.                           {
  595.                           *(yytext+strlen((char *)yytext)-1) = '\0';
  596.  
  597.                           if (yytext[1] == '/')
  598.                              {
  599.                              HandlePath(yytext+1);
  600.                              }
  601.                           else
  602.                              {
  603.                              HandleItem(yytext+1);
  604.                              }
  605.                           return QSTRING;
  606.                           }
  607.                        }
  608.  
  609. {bqstring}             {
  610.                        if (ACTION == editfiles)
  611.                           {
  612.                           *(yytext+strlen((char *)yytext)-1) = '\0';
  613.                           HandleEdit(CURRENTPATH,CURRENTITEM,yytext+1);
  614.                           return QSTRING;
  615.                           }
  616.                        else if (ACTION == groups)
  617.                           {
  618.                           HandleItem(yytext);
  619.                           return ITEM;
  620.                           }
  621.                        else if (ACTION == control)
  622.                           {
  623.                           *(yytext+strlen((char *)yytext)-1) = '\0';
  624.                           HandleItem(yytext+1);
  625.                           Debug1("Quoted macro string %s\n",yytext+1);
  626.                           return QSTRING;
  627.                           }
  628.                        else
  629.                           {
  630.                           *(yytext+strlen((char *)yytext)-1) = '\0';
  631.  
  632.                           if (yytext[1] == '/')
  633.                              {
  634.                              HandlePath(yytext+1);
  635.                              }
  636.                           else
  637.                              {
  638.                              HandleItem(yytext+1);
  639.                              }
  640.                           return QSTRING;
  641.                           }
  642.                        }
  643.  
  644.  
  645. {varpath}              {
  646.                        IsVarString(yytext);        /* Syntax check */
  647.                        HandleVarpath(yytext);
  648.                        return VARPATH;
  649.                        }
  650.  
  651. {varitem}              {
  652.                        if (ACTION_IS_LINK || ACTION_IS_LINKCHILDREN)
  653.                           {
  654.                           if (strlen(LINKTO) == 0)
  655.                              {
  656.                              HandlePath(yytext);
  657.                              return PATH;
  658.                              }
  659.                           }
  660.  
  661.                        HandleWildcard(yytext);
  662.  
  663.                        if (IsVarString(yytext))
  664.                           {
  665.                           return VARITEM;
  666.                           }
  667.  
  668.                        return WILDCARD;
  669.                        }
  670.  
  671.  
  672. {wildcard}             {
  673.                        Debug1("LEX: wildcard, I think I lov you...but i wanna know for sure\n");
  674.  
  675.                        if (ACTION_IS_LINK || ACTION_IS_LINKCHILDREN)
  676.                           {
  677.                           if (strlen(LINKTO) == 0)
  678.                              {
  679.                              HandlePath(yytext);
  680.                              return PATH;
  681.                              }
  682.                           }
  683.  
  684.                        if (IsVarString(yytext))
  685.                           {
  686.                           HandleWildcard(yytext);
  687.                           return VARITEM;
  688.                           }
  689.  
  690.                        HandleWildcard(yytext);
  691.                        return WILDCARD;
  692.                        }
  693.  
  694.  
  695.  
  696.  
  697. .                      {
  698.                        return yytext[0];
  699.                        }
  700.  
  701. %%
  702.  
  703. /* EOF */
  704.